<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/20
 * Time: 12:08
 */

namespace app\admin\controller\goods;


use app\admin\controller\BaseController;
use think\Controller;

class Category extends BaseController
{
    public function page(){
        $category=new \app\admin\model\Category();
        
        return $this->fetch("index");
    }

    //添加分类
    public function add(){

        return $this->fetch();
    }

    public function create(){

    }

    //添加，编辑商品
    public function edit(){
        $category=new \app\admin\model\Category();
        if($this->request->isGet()){
            if($this->request->has("id")){//编辑
                $id=$this->request->get("id");
                $item=$category->find([
                    "id"    =>$id
                ]);
                //dump($item);die();
                $this->assign("item",$item);
            }else{//添加

            }
            $items=$category->select();
            $this->assign("items",$items);
            return $this->fetch("goods/category/edit");
        }else{
            $data=$this->request->post();
            if(array_key_exists("file",$data)){
                unset($data["file"]);
            }
            if(!empty($data["id"])){//更新数据
                $category::update($data);
                return json([
                    "code"      =>200,
                    "msg"       =>"update success"
                ]);
            }else{//插入数据
                $category->insert($data);
                return json([
                    "code"      =>200,
                    "msg"       =>"insert success"
                ]);
            }

        }
    }
}